package org.springblade.modules.admin.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.Func;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.modules.admin.entity.ElevatorReportConfig;
import org.springblade.modules.admin.mapper.ElevatorReportConfigMapper;
import org.springblade.modules.admin.service.ElevatorReportConfigService;
import org.springframework.transaction.annotation.Transactional;

@AllArgsConstructor
@Service
public class ElevatorReportConfigServiceImpl extends ServiceImpl<ElevatorReportConfigMapper, ElevatorReportConfig> implements ElevatorReportConfigService{

	@Override
	@Transactional(rollbackFor = Exception.class)
	public Boolean submit(List<ElevatorReportConfig> entityList) {
		// 清除已有数据
		super.remove(Wrappers.<ElevatorReportConfig>lambdaQuery().eq(ElevatorReportConfig::getTenantId, AuthUtil.getTenantId()));
		// 更新新数据
		if(Func.isNotEmpty(entityList)){
			entityList.forEach(e -> {
				e.setTenantId(AuthUtil.getTenantId());
				e.setCreateTime(DateUtil.date());
				e.setCreateUser(AuthUtil.getUserId());
			});
			return super.saveBatch(entityList);
		}else {
			return Boolean.TRUE;
		}
	}

	@Override
	public List<ElevatorReportConfig> tree(String tenantId) {
		return baseMapper.tree(tenantId);
	}
}
